#!/bin/bash

ifeq (,$(TOP_DIR))
TOP_DIR := $(shell pwd)/..
CURRENT_DIR := $(shell pwd)
else
CURRENT_DIR := $(TOP_DIR)/kernel-driver
endif

ifeq (,$(KDIR))
KDIR := $(TOP_DIR)/../vmlinux
endif

OBJS := qtsm.c

ccflags-y += -I $(TOP_DIR)/../vmlinux/include/linux

KO_TARGET := $(CURRENT_DIR)/$(basename $(OBJS)).ko

obj-m := $(basename $(OBJS)).o

ko_module:
	@echo "************ Start Make KO-Module ************"
	make -C $(KDIR) M=$(CURRENT_DIR) modules
	mkdir -p $(TOP_DIR)/output
	cp $(KO_TARGET) $(TOP_DIR)/output/
	@echo "************ Make KO-Module Finished ************"

clean:
	make -C $(KDIR) M=$(CURRENT_DIR) clean
